#region Copyright (c) 2006-2010 Widgetsphere LLC, All Rights Reserved
//--------------------------------------------------------------------- *
//                          Widgetsphere  LLC                           *
//             Copyright (c) 2006-2010 All Rights reserved              *
//                                                                      *
//                                                                      *
//This file and its contents are protected by United States and         *
//International copyright laws.  Unauthorized reproduction and/or       *
//distribution of all or any portion of the code contained herein       *
//is strictly prohibited and will result in severe civil and criminal   *
//penalties.  Any violations of this copyright will be prosecuted       *
//to the fullest extent possible under law.                             *
//                                                                      *
//THE SOURCE CODE CONTAINED HEREIN AND IN RELATED FILES IS PROVIDED     *
//TO THE REGISTERED DEVELOPER FOR THE PURPOSES OF EDUCATION AND         *
//TROUBLESHOOTING. UNDER NO CIRCUMSTANCES MAY ANY PORTION OF THE SOURCE *
//CODE BE DISTRIBUTED, DISCLOSED OR OTHERWISE MADE AVAILABLE TO ANY     *
//THIRD PARTY WITHOUT THE EXPRESS WRITTEN CONSENT OF WIDGETSPHERE LLC   *
//                                                                      *
//UNDER NO CIRCUMSTANCES MAY THE SOURCE CODE BE USED IN WHOLE OR IN     *
//PART, AS THE BASIS FOR CREATING A PRODUCT THAT PROVIDES THE SAME, OR  *
//SUBSTANTIALLY THE SAME, FUNCTIONALITY AS ANY WIDGETSPHERE PRODUCT.    *
//                                                                      *
//THE REGISTERED DEVELOPER ACKNOWLEDGES THAT THIS SOURCE CODE           *
//CONTAINS VALUABLE AND PROPRIETARY TRADE SECRETS OF WIDGETSPHERE,      *
//INC.  THE REGISTERED DEVELOPER AGREES TO EXPEND EVERY EFFORT TO       *
//INSURE ITS CONFIDENTIALITY.                                           *
//                                                                      *
//THE END USER LICENSE AGREEMENT (EULA) ACCOMPANYING THE PRODUCT        *
//PERMITS THE REGISTERED DEVELOPER TO REDISTRIBUTE THE PRODUCT IN       *
//EXECUTABLE FORM ONLY IN SUPPORT OF APPLICATIONS WRITTEN USING         *
//THE PRODUCT.  IT DOES NOT PROVIDE ANY RIGHTS REGARDING THE            *
//SOURCE CODE CONTAINED HEREIN.                                         *
//                                                                      *
//THIS COPYRIGHT NOTICE MAY NOT BE REMOVED FROM THIS FILE.              *
//--------------------------------------------------------------------- *
#endregion
using System;
using System.Collections;
using System.Drawing;
using System.Windows.Forms;

namespace Widgetsphere.Generator
{
	internal enum ImageConstants
	{
		Attribute,
		Column,
    ColumnPrimaryKey,
		ColumnForeignKey,
		Database,
    Domain,
		Table,
		TableType,
		Package,
		Packages,
		Error,
		Relationship,
		Entity,
		TableAssociative,
		Tables,
		FolderClose,
		FolderOpen,
		UI,
		Up,
		Down,
    CustomView,
    CustomViews,
    CustomViewColumn,
    CustomRetrieveRule,
    CustomRetrieveRules,
    Parameter,
    CustomStoredProcedure,
    CustomStoredProcedures,
    CustomStoredProcedureColumn,
		TableNonGen,
		ColumnInherit,
  }

	internal class ImageHelper
	{
		internal static Hashtable ImageMapper = new Hashtable();
		internal static ImageList ImageList = null;

		private ImageHelper()
		{
		}

		static ImageHelper()
		{
			GetImageList();
		}

    public static Icon GetIcon(ImageConstants image)
    {
      Icon retval = null;
      switch(image)
      {
        case ImageConstants.Attribute:
          retval = GetIcon("Attribute.ico");
          break;
				case ImageConstants.Column:
					retval = GetIcon("Column.ico");
					break;
				case ImageConstants.ColumnInherit:
					retval = GetIcon("ColumnInherit.ico");
					break;
				case ImageConstants.ColumnPrimaryKey:
          retval = GetIcon("ColumnPrimaryKey.ico");
          break;
				case ImageConstants.ColumnForeignKey:
					retval = GetIcon("AttributeForeignKey.ico");
          break;					
        case ImageConstants.Database:
          retval = GetIcon("Database.ico");
          break;
        case ImageConstants.Domain:
          retval = GetIcon("Domain.ico");
          break;
				case ImageConstants.Table:
					retval = GetIcon("Table.ico");
					break;
				case ImageConstants.TableType:
					retval = GetIcon("TableType.ico");
					break;
				case ImageConstants.Error:
          retval = GetIcon("Error.ico");
          break;
        case ImageConstants.Relationship:
          retval = GetIcon("Relationship.ico");
          break;
        case ImageConstants.Entity:
          retval = GetIcon("Table.ico");
          break;
        case ImageConstants.TableAssociative:
          retval = GetIcon("TableAssociative.ico");
          break;
        case ImageConstants.Tables:
          retval = GetIcon("Tables.ico");
          break;
        case ImageConstants.FolderClose:
          retval = GetIcon("FolderClose.ico");
          break;
        case ImageConstants.FolderOpen:
          retval = GetIcon("FolderOpen.ico");
          break;
        case ImageConstants.UI:
          retval = GetIcon("UI.ico");
          break;
        case ImageConstants.Up:
          retval = GetIcon("Up.ico");
          break;
        case ImageConstants.Down:
          retval = GetIcon("Down.ico");
          break;
        case ImageConstants.Package:
          retval = GetIcon("Package.ico");
          break;
        case ImageConstants.Packages:
          retval = GetIcon("Packages.ico");
          break;
        case ImageConstants.CustomView:
          retval = GetIcon("CustomView.ico");
          break;
        case ImageConstants.CustomViews:
          retval = GetIcon("CustomViews.ico");
          break;
        case ImageConstants.CustomViewColumn:
          retval = GetIcon("CustomViewColumn.ico");
          break;
        case ImageConstants.CustomRetrieveRule:
          retval = GetIcon("CustomRetrieveRule.ico");
          break;
        case ImageConstants.CustomRetrieveRules:
          retval = GetIcon("CustomRetrieveRules.ico");
          break;
        case ImageConstants.Parameter:
          retval = GetIcon("Parameter.ico");
          break;
        case ImageConstants.CustomStoredProcedure:
          retval = GetIcon("CustomStoredProcedure.ico");
          break;
        case ImageConstants.CustomStoredProcedures:
          retval = GetIcon("CustomStoredProcedures.ico");
          break;
				case ImageConstants.CustomStoredProcedureColumn:
					retval = GetIcon("CustomStoredProcedureColumn.ico");
					break;
				case ImageConstants.TableNonGen:
					retval = GetIcon("TableNonGen.ico");
					break;
				default:
          throw new Exception("Image not found!");
      }

      return retval;
    }

		internal static int GetImageIndex(ImageConstants image)
		{
			return (int)ImageMapper[image];
		}

		internal static ImageList GetImageList()
		{
			if (ImageList == null)
			{
				ImageList = new ImageList();
				ImageList.Images.Clear();
				Array a = Enum.GetValues(typeof(ImageConstants));
				int index = 0;
				foreach(ImageConstants ic in a)
				{
					Icon icon = GetIcon(ic);
					ImageMapper.Add(ic, index);
					ImageList.Images.Add(icon);
					index++;
				}
			}
			return ImageList;
		}

		internal static Icon GetIcon(string name)
		{
			return new Icon(GetProjectFileAsStream(name));
		}

		private static System.IO.Stream GetProjectFileAsStream(string fileName)
		{
			try
			{
				System.Reflection.Assembly asbly = System.Reflection.Assembly.GetExecutingAssembly();
				System.IO.Stream stream = asbly.GetManifestResourceStream(asbly.GetName().Name + ".Images." + fileName);
				System.IO.StreamReader sr = new System.IO.StreamReader(stream, System.Text.Encoding.UTF8);
				return sr.BaseStream;
			}
			catch(Exception ex)
			{
				throw;
			}
		}

	}
}
